import { deleteRuleAPI, fetchRuleListAPI } from '@/api/car/billingApi'

const actions = {
  /* 发送请求获取计费规则列表的action */
  async fetchRuleList(context, pageParams) {
    const { data } = await fetchRuleListAPI(pageParams)
    context.commit('updateRuleList', data)
  },
  /* 发送请求删除计费规则的action */
  async deleteRule(context, id) {
    await deleteRuleAPI(id)
    return '删除计费规则成功'
  }
}
const mutations = {
  /* 更新计费规则的mutation */
  updateRuleList(state, ruleListInfo) {
    state.ruleListInfo = ruleListInfo
  }
}
const state = () => {
  return {
    ruleListInfo: {}
  }
}

const getters = {
  ruleList: state => state.ruleListInfo.rows,
  total: state => state.ruleListInfo.total
}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
